extends IBasicComponent


class_name FiniteState
"""
IFiniteState的默认实现
"""


## 进入状态时触发
@export var event_enter: IEventActuator = null
## 退出状态时触发
@export var event_exit: IEventActuator = null
## 状态检测
@export var state_conditions: Array[IStateCondition] = []


# 是否进入
var __is_running: bool = false


func __check_exports() -> Dictionary:
    return IComponent.merge({
        "state_conditions": [IComponent.find_children.bind(self, func(x): return x is IStateCondition, state_conditions)],
    }, super.__check_exports())

func enter() -> void:
    __is_running = true

    IEventActuator.safe_execute(event_enter)
    for condition in state_conditions:
        condition.enter()

func exit() -> void:
    for condition in state_conditions:
        condition.exit()
    IEventActuator.safe_execute(event_exit)
    __is_running = false

func update(delta: float) -> void:
    for condition in state_conditions:
        if condition.is_enable:
            condition.update(delta)
